package com.government.web.controller.org;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.government.common.annotation.RepeatSubmit;
import com.government.common.core.domain.BaseTreeVo;
import com.government.org.bo.OrgInfoBO;
import com.government.org.vo.OrgInfoVO;
import com.government.org.vo.OrgTreeVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.government.common.annotation.Log;
import com.government.common.core.controller.BaseController;
import com.government.common.core.domain.AjaxResult;
import com.government.common.enums.BusinessType;
import com.government.org.domain.OrgInfo;
import com.government.org.service.IOrgInfoService;
import com.government.common.utils.poi.ExcelUtil;
import com.government.common.core.page.TableDataInfo;

/**
 * 主管单位Controller
 * 
 * @author system
 * @date 2023-09-14
 */
@RestController
@RequestMapping("/org/org")
public class OrgInfoController extends BaseController
{
    @Autowired
    private IOrgInfoService orgInfoService;

    /**
     * 查询主管单位列表（分页）
     */
    @PreAuthorize("@ss.hasPermi('org:org:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrgInfoBO orgInfo)
    {
        startPage();
        List<OrgInfoVO> list = orgInfoService.selectOrgInfoList(orgInfo);
        return getDataTable(list);
    }

    /**
     * 查询主管单位列表树
     */
    @GetMapping("/getAll")
    public AjaxResult getAll()
    {
        List<OrgTreeVO> list = orgInfoService.getAll();
        return success(list);
    }

    /**
     * 查询主管单位列表
     */
    @GetMapping("/getAllOrgList")
    public AjaxResult getAllOrgList()
    {
        List<OrgInfo> list = orgInfoService.getAllOrgList();
        return success(list);
    }


    /**
     * 导出主管单位列表
     */
    @PreAuthorize("@ss.hasPermi('org:org:export')")
    @Log(title = "主管单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrgInfoBO orgInfo)
    {
        List<OrgInfoVO> list = orgInfoService.selectOrgInfoList(orgInfo);
        ExcelUtil<OrgInfoVO> util = new ExcelUtil<OrgInfoVO>(OrgInfoVO.class);
        util.exportExcel(response, list, "主管单位数据");
    }

    /**
     * 获取主管单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('org:org:query')")
    @GetMapping(value = "/{orgId}")
    public AjaxResult getInfo(@PathVariable("orgId") Long orgId)
    {
        return success(orgInfoService.selectOrgInfoByOrgId(orgId));
    }

    /**
     * 新增主管单位
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('org:org:add')")
    @Log(title = "主管单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrgInfoBO orgInfo)
    {
        return toAjax(orgInfoService.insertOrgInfo(orgInfo));
    }

    /**
     * 修改主管单位
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('org:org:edit')")
    @Log(title = "主管单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrgInfo orgInfo)
    {
        return toAjax(orgInfoService.updateOrgInfo(orgInfo));
    }

    /**
     * 删除主管单位
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('org:org:remove')")
    @Log(title = "主管单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orgId}")
    public AjaxResult remove(@PathVariable Long orgId)
    {
        return toAjax(orgInfoService.deleteOrgInfoByOrgId(orgId));
    }

    /**
     * 获取部门所属树
     */
    @GetMapping("/getParentOrgTree")
    public AjaxResult getParentOrgTree(Long orgId)
    {
        return AjaxResult.success(orgInfoService.getParentOrgTree(orgId));
    }

    /**
     * 部门主管政策
     */
    @GetMapping("/findOrgPolicy")
    public AjaxResult findOrgPolicy(Long orgId)
    {
        return AjaxResult.success(orgInfoService.findOrgPolicy(orgId));
    }
}
